package com.zhao.Others;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 1.当前日期 yyyy-MM-dd
 * 2.当前时间 hh:mm:ss
 * 3.当前日期 yyyyMMdd
 * 4.当前时间 hhmmss
 */
public class DateAndTimeObject {

    public static SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
    public static SimpleDateFormat simpleOnlyNumberDateFormat = new SimpleDateFormat("yyyyMMdd");
    public static SimpleDateFormat simpleTimeFormat = new SimpleDateFormat("HH:mm:ss");
    public static SimpleDateFormat simpleOnlyNumberTimeFormat = new SimpleDateFormat("HHmmss");

    public static String getNowDate(){
        simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
        String date = simpleDateFormat.format(new Date());
        return date;
    }

    public static String getNowTime(){
        simpleTimeFormat = new SimpleDateFormat("HH:mm:ss");
        return simpleTimeFormat.format(new Date());
    }

    public static String getOnlyNumberOfNowDate(){
        simpleOnlyNumberDateFormat = new SimpleDateFormat("yyyyMMdd");
        return simpleOnlyNumberDateFormat.format(new Date());
    }

    public static String getOnlyNumberOfNowTime(){
        simpleOnlyNumberTimeFormat = new SimpleDateFormat("HHmmss");
        return simpleOnlyNumberTimeFormat.format(new Date());
    }

    public static void main(String[] args) {
        System.out.println(getNowDate());
        System.out.println(getNowTime());
        System.out.println(getOnlyNumberOfNowDate());
        System.out.println(getOnlyNumberOfNowTime());
    }
}
